package com.topnav.mc.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.js.lib.mybitsplus.page.JsPage;
import com.js.lib.result.ApiResult;
import com.topnav.mc.admin.entity.DeviceOnlineTotal;
import com.topnav.mc.admin.entity.bean.DeviceOnlineTotalBean;
import com.topnav.mc.admin.entity.param.DeviceOnlineTotalParam;
import com.topnav.mc.admin.entity.wrapper.DeviceOnlineTotalWrapper;
import com.topnav.mc.admin.service.IDeviceOnlineTotalService;
import com.topnav.mc.base.mc.McController;
import com.topnav.mc.base.mc.McPage;
import com.topnav.mc.exception.ExceptionMsg;
import com.topnav.mc.uitls.ResultErrorUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 设备在线统计
 * @Author: kenny
 * @Date: 2023/11/1 9:13
 */
@Api(value = "admin/device/online", tags = "设备在线时长")
@RestController
@CrossOrigin
@RequestMapping("admin/device/online")
public class DeviceOnlineTotalController extends McController<
       DeviceOnlineTotal, DeviceOnlineTotalBean, DeviceOnlineTotalParam, IDeviceOnlineTotalService, DeviceOnlineTotalWrapper> {

    @Autowired
    private IDeviceOnlineTotalService deviceOnlineTotalService;


    /**
     * 设备在线时长统计
     * @param page
     * @return
     */
    @PostMapping("/query/sum/page")
    @ResponseBody
    public ApiResult<List<DeviceOnlineTotalBean>> querySumPage(@Validated(IPage.class) @RequestBody McPage<DeviceOnlineTotalParam> page) {

        if (page.getWhere() == null){
            //查询条件参数必须提供
            return (ApiResult<List<DeviceOnlineTotalBean>>) ResultErrorUtil.apibyExceptionMsg(ExceptionMsg.ERROR_PARAM_CONDITION_NOT_PROVIDED);
        }
        if (page.getWhere().getFromTime() == null || page.getWhere().getToTime() == null){
            //开始时间和结束必须提供
            return (ApiResult<List<DeviceOnlineTotalBean>>) ResultErrorUtil.apibyExceptionMsg(ExceptionMsg.ERROR_PARAM_START_TIME_AND_END_TIME_NOT_PROVIDED);
        }
        Page<DeviceOnlineTotalBean> page1 = deviceOnlineTotalService.pageInfo0(page.getPage(), getNewWrapper(page.getWhere()));
        return (ApiResult<List<DeviceOnlineTotalBean>>) ApiResult.ok(page1);
    }

}
